home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr29 / memsize.zip / PROFILE.CPP < prev    next >
Text File  |  1995-01-04  |  9KB  |  239 lines

  1. /**************************************************************** PROFILE.CPP
  2.  *                                                                          *
  3.  *                         "Profile Path" Dialog                            *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <string.h>
  12.  
  13. #include "support.h"
  14. #include "profile.h"
  15.  
  16.  
  17. /****************************************************************************
  18.  *                                                                          *
  19.  *                     Definitions & Declarations                           *
  20.  *                                                                          *
  21.  ****************************************************************************/
  22.  
  23. enum { ENTRY, ERR } ;
  24.  
  25. static METHODFUNCTION InitDlg ;
  26. static METHODFUNCTION Command ;
  27. static METHODFUNCTION OK ;
  28. static METHODFUNCTION Cancel ;
  29.  
  30.   // Global Data
  31.  
  32. static SHORT id ;
  33. static PBYTE Path ;
  34. static int   PathSize ;
  35.  
  36.  
  37. /****************************************************************************
  38.  *                                                                          *
  39.  *      Dialog Message Processor                                            *
  40.  *                                                                          *
  41.  ****************************************************************************/
  42.  
  43. extern MRESULT EXPENTRY ProfileProcessor
  44. (
  45.   HWND hwnd,
  46.   USHORT msg,
  47.   MPARAM mp1,
  48.   MPARAM mp2
  49. )
  50. {
  51.  /***************************************************************************
  52.   *                             Declarations                                *
  53.   ***************************************************************************/
  54.  
  55.   static METHOD Methods [] =
  56.   {
  57.     { WM_INITDLG, InitDlg },
  58.     { WM_COMMAND, Command }
  59.   } ;
  60.  
  61.  /***************************************************************************
  62.   * Dispatch the message according to the method table and return the       *
  63.   *   result.  Any messages not defined above get handled by the system     *
  64.   *   default dialog processor.                                             *
  65.   ***************************************************************************/
  66.  
  67.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  68. }
  69.  
  70. /****************************************************************************
  71.  *                                                                          *
  72.  *      Initialize Dialog                                                   *
  73.  *                                                                          *
  74.  ****************************************************************************/
  75.  
  76. static MRESULT APIENTRY InitDlg
  77.   HWND hwnd, 
  78.   USHORT msg,
  79.   MPARAM mp1, 
  80.   MPARAM mp2
  81. )
  82. {
  83.  /***************************************************************************
  84.   * Get parameters from initialization message.                             *
  85.   ***************************************************************************/
  86.  
  87.   PPROFILE_PARMS Parms = (PPROFILE_PARMS) ( PVOIDFROMMP ( mp2 ) ) ;
  88.  
  89.  /***************************************************************************
  90.   * Save parameter data.                                                    *
  91.   ***************************************************************************/
  92.  
  93.   id = Parms->id ;
  94.   Path = Parms->Path ;
  95.   PathSize = Parms->PathSize ;
  96.  
  97.  /***************************************************************************
  98.   * Set the dialog help instance.                                           *
  99.   ***************************************************************************/
  100.  
  101.   WinSetWindowUShort ( hwnd, QWS_ID, Parms->id ) ;
  102.   if ( Parms->hwndHelp )
  103.   {
  104.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  105.   }
  106.  
  107.  /***************************************************************************
  108.   * Set the entry field contents.                                           *
  109.   ***************************************************************************/
  110.  
  111.   WinSetDlgItemText ( hwnd, id+ENTRY, Path ) ;
  112.  
  113.  /***************************************************************************
  114.   * Return no error.                                                        *
  115.   ***************************************************************************/
  116.  
  117.   return ( MRFROMSHORT ( FALSE ) ) ;
  118. }
  119.  
  120. /****************************************************************************
  121.  *                                                                          *
  122.  *      Process commands received by the dialog.                            *
  123.  *                                                                          *
  124.  ****************************************************************************/
  125.  
  126. static MRESULT APIENTRY Command
  127.   HWND hwnd, 
  128.   USHORT msg, 
  129.   MPARAM mp1, 
  130.   MPARAM mp2
  131. )
  132. {
  133.  /***************************************************************************
  134.   * Local Declarations                                                      *
  135.   ***************************************************************************/
  136.  
  137.   static METHOD Methods [] =
  138.   {
  139.     { DID_OK,     OK     },
  140.     { DID_CANCEL, Cancel },
  141.   } ;
  142.  
  143.  /***************************************************************************
  144.   * Dispatch the message without a default message processor.               *
  145.   ***************************************************************************/
  146.  
  147.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), PFNWP(NULL) ) ) ;
  148. }
  149.  
  150. /****************************************************************************
  151.  *                                                                          *
  152.  *      Process the dialog's OK button being pressed.                       *
  153.  *                                                                          *
  154.  ****************************************************************************/
  155.  
  156. static MRESULT APIENTRY OK
  157.   HWND hwnd, 
  158.   USHORT msg, 
  159.   MPARAM mp1, 
  160.   MPARAM mp2
  161. )
  162. {
  163.  /***************************************************************************
  164.   * Verify the entered path.                                                *
  165.   ***************************************************************************/
  166.  
  167.   BYTE Name [256] ;
  168.   WinQueryDlgItemText ( hwnd, id+ENTRY, sizeof(Name), Name ) ;
  169.  
  170.   BYTE FullPath [256] ;
  171.   if ( DosQueryPathInfo ( Name, FIL_QUERYFULLNAME, FullPath, sizeof(FullPath) ) )
  172.   {
  173.     PSZ Message = PSZ ( "ERROR: Not a valid path." ) ;
  174.     WinSetDlgItemText ( hwnd, id+ERR, Message ) ;
  175.     WinAlarm ( HWND_DESKTOP, WA_ERROR ) ;
  176.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, id+ENTRY ) ) ;
  177.     return ( 0 ) ;
  178.   }
  179.  
  180.   FILESTATUS3 Status ;
  181.   if ( DosQueryPathInfo ( FullPath, FIL_STANDARD, &Status, sizeof(Status) ) )
  182.   {
  183.     PSZ Message = PSZ ( "ERROR: Path does not exist." ) ;
  184.     WinSetDlgItemText ( hwnd, id+ERR, Message ) ;
  185.     WinAlarm ( HWND_DESKTOP, WA_ERROR ) ;
  186.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, id+ENTRY ) ) ;
  187.     return ( 0 ) ;
  188.   }
  189.  
  190.   if ( ! ( Status.attrFile & FILE_DIRECTORY ) )
  191.   {
  192.     PSZ Message = PSZ ( "ERROR: Specified path is not a directory." ) ;
  193.     WinSetDlgItemText ( hwnd, id+ERR, Message ) ;
  194.     WinAlarm ( HWND_DESKTOP, WA_ERROR ) ;
  195.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, id+ENTRY ) ) ;
  196.     return ( 0 ) ;
  197.   }
  198.  
  199.  /***************************************************************************
  200.   * Return the full path to the caller.                                     *
  201.   ***************************************************************************/
  202.  
  203.   strncpy ( PCHAR(Path), PCHAR(FullPath), PathSize ) ;
  204.  
  205.  /***************************************************************************
  206.   * Dismiss the dialog with a TRUE status.                                  *
  207.   ***************************************************************************/
  208.  
  209.   WinDismissDlg ( hwnd, TRUE ) ;
  210.  
  211.   return ( 0 ) ;
  212. }
  213.  
  214. /****************************************************************************
  215.  *                                                                          *
  216.  *      Process the dialog's being cancelled.                               *
  217.  *                                                                          *
  218.  ****************************************************************************/
  219.  
  220. static MRESULT APIENTRY Cancel
  221.   HWND hwnd, 
  222.   USHORT msg, 
  223.   MPARAM mp1, 
  224.   MPARAM mp2
  225. )
  226. {
  227.  /***************************************************************************
  228.   * Dismiss the dialog with a TRUE status.                                  *
  229.   ***************************************************************************/
  230.  
  231.   WinDismissDlg ( hwnd, FALSE ) ;
  232.  
  233.   return ( 0 ) ;
  234. }
  235.